package com.bafa.gadgets;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bafa.debug.Debug;
import com.bafa.gadgets.events.*;
import com.bafa.objects.PageBean;
import com.bafa.services.RetrieveServices;

public class GadgetServlet extends HttpServlet {

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 String page = request.getParameter("page");
		 PageBean pageBeanTemp = RetrieveServices.getPage(page);
		 PageBean pageBean = new PageBean(pageBeanTemp);
		try{
		 Class c = Class.forName("com.bafa.gadgets.events."+pageBean.getEvent());
		Event event = (Event)c.newInstance();
		event.doEvent(request,response,pageBean);
		Debug.debug(this.getClass(),"doEvent","This is the page we're going to: "+pageBean.getMainbody());
		request.getRequestDispatcher(pageBean.getMainbody()).forward(request,response);
		}catch(Exception e){
			Debug.printStackTrace(e);
		}
	}

	

}
